package com.jubaozan.service.platform.controller;

import com.jubaozan.c3.framework.constants.Constants;
import com.jubaozan.c3.framework.utils.ResultHolder;
import com.jubaozan.service.platform.decorator.PlatformRegisterDecorator;
import com.jubaozan.service.platform.exception.PlatformException;
import com.jubaozan.service.platform.vo.*;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiModelProperty;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import javax.validation.Valid;

/**
 * @ClassName PlatformRegisterController
 * @Description 个体平台入驻相关接口Controller
 * @Author TanRuixiang
 * @Date 2020/9/17 16:24
 * @Version 1.0
 **/
@Api(tags = {"个体平台入驻相关接口"}, value = "个体平台入驻相关接口")
@RestController
@RequestMapping("/store")
@Validated
public class PlatformRegisterController {

    private final PlatformRegisterDecorator platformRegisterDecorator;

    public PlatformRegisterController(PlatformRegisterDecorator platformRegisterDecorator){
        this.platformRegisterDecorator = platformRegisterDecorator;
    }

    @ApiOperation(value = "个体平台或企业基本信息注册")
    @PostMapping({"/", ""})
    public ResultHolder<Boolean> register(@Valid @RequestBody PlatformInfoVO platformInfoVO) throws PlatformException {
        return ResultHolder.success(platformRegisterDecorator.register(platformInfoVO));
    }

    @ApiOperation(value = "个体平台资料提交")
    @PostMapping("/personal")
    public ResultHolder<Boolean> submit(@Valid @RequestBody PlatformSubmitVO platformSubmitVO){
        return ResultHolder.success(platformRegisterDecorator.submit(platformSubmitVO));
    }

    @ApiOperation(value = "企业入驻资料提交")
    @PostMapping("/company")
    public ResultHolder<Boolean> companySubmit(@Valid @RequestBody PlatformCompanySubmitVO platformCompanySubmitVO){
        return ResultHolder.success(platformRegisterDecorator.companySubmit(platformCompanySubmitVO));
    }

    @ApiOperation(value = "查询个体平台信息")
    @GetMapping("/{unionid}")
    public ResultHolder<StoreVO> queryStore(@ApiParam(value = "unionid", example = "oqXaH0_pMwRsvVK9YSrbbV-v0BE0")
                                               @PathVariable("unionid") String unionid){
        return ResultHolder.success(platformRegisterDecorator.queryStore(unionid));
    }

    @ApiOperation(value = "检查入驻审核状态和情况")
    @PostMapping("audit/check/{unionid}")
    public ResultHolder<StoreVO> checkStore(@ApiParam(value = "unionid", example = "oqXaH0_pMwRsvVK9YSrbbV-v0BE0")
                                               @PathVariable("unionid") String unionid){
        return ResultHolder.success(platformRegisterDecorator.checkStore(unionid));
    }

    @ApiOperation(value = "邀请人信息和审核进度查询")
    @GetMapping("audit/progress/{unionid}")
    public ResultHolder<PlatformProgressVO> queryProgress(@ApiParam(value = "unionid", example = "oqXaH0_pMwRsvVK9YSrbbV-v0BE0")
                                                  @PathVariable("unionid") String unionid){
        return ResultHolder.success(platformRegisterDecorator.queryProgress(unionid));
    }

    @ApiOperation(value = "获取待审核的团长数量")
    @GetMapping("audit/teams")
    public ResultHolder<Integer> getTeamsNum(@RequestHeader(Constants.KEY_X_C3_STOREID)Long storeId,Integer level){
        return ResultHolder.success(platformRegisterDecorator.getAuditTeamsNum(storeId, level));
    }

    @ApiOperation(value = "小程序配置")
    @GetMapping("/configure")
    public ResultHolder<ConfigureProperties> configure(){
        return ResultHolder.success(platformRegisterDecorator.configure());
    }

}
